<template>
  <ToolbarButton
    icon="i-ri-bold"
    title="粗体"
    shortcut="Ctrl+B"
    :active="isActive"
    @click="handleClick"
  />
</template>

<script setup lang="ts">
import { computed, inject, type Ref } from "vue";
import type { Editor } from "@tiptap/vue-3";
import ToolbarButton from "../../../button/index.vue";

defineOptions({
  name: "Bold",
});

// 注入编辑器实例
const editor = inject<Ref<Editor>>("editor");

const isActive = computed(() => {
  return editor?.value?.isActive("bold");
});

const handleClick = () => {
  editor?.value?.chain().focus().toggleBold().run();
};
</script>
